#include "stdafx.h"
#include "BoomEffective.h"


CBoomEffective::CBoomEffective()
{
	SetImage();
	m_StateId = 0;
	m_isClear = false;
}


CBoomEffective::~CBoomEffective()
{
	for (int i = 0; i < MAX_BOOMIMAGE_COUNT; i++) {
		cvReleaseImage((m_Bimg + i));
	}
}


void CBoomEffective::SetImage()
{
	char filename[40];
	for (int i = 0; i < MAX_BOOMIMAGE_COUNT; i++) {
		sprintf_s(filename, "./pic/bomb/0%d.jpg", i + 1);
		m_Bimg[i] = cvLoadImage(filename);
	}
}


void CBoomEffective::BoomImageChange()
{
	if (m_StateId < 3) m_StateId++;
	else m_isClear = true;
}


CBoomEffective::CBoomEffective(int x, int y)
{
	m_StateId = 0;
	SetImage();
	m_pos.x = x, m_pos.y = y;
	m_isClear = false;
}


void CBoomEffective::DrawToBack(IplImage * Bg, int MapMoveDis)
{
	int keyb = 0, keyr = 0, keyg = 0;
	if (m_pos.x - MapMoveDis < Bg->width && m_pos.x - MapMoveDis >= -m_Bimg[m_StateId]->width + 1)
		CTools::DrawToBackground(m_pos.x - MapMoveDis, m_pos.y, Bg, m_Bimg[m_StateId], keyb, keyg, keyr);
}


bool CBoomEffective::GetClearType()
{
	return m_isClear;
}
